package cate.game.play.skill.passive.fairy;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.AppendMove;
import cate.game.play.proce.move.AppendMoveHandler;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.proce.turn.TurnCtx;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 当自身生命值低于30%时，发动技能与随机1名敌方英雄交换生命值比例，优先选择处于【黄泉梦境】的英雄，
 * 若目标最大生命值大于孟婆2倍，则发动失败，每场战斗仅发动1次，无论成功与否，孟婆都会恢复自身攻击力100%的生命值
 */
public class 孟婆灵器PH extends PassiveHandler implements AppendMoveHandler {

	private int 血量;

	private int 追加技能;

	//血量=3000&追加技能=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		追加技能 = args.getInt("追加技能", 0);
	}

	private boolean append;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (append) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		Skill appendSkill = move.getCfg().skill.buildById(skill.owner, 追加技能);
		if (appendSkill == null) {
			return;
		}
		move.getTurn().addAppend(new AppendMove(skill.owner, appendSkill, this));
	}

	@Override
	public boolean inValid(TurnCtx turn, AppendMove appendMove) {
		return append;
	}

	@Override
	public void beforeAppendMove(TurnCtx turn, AppendMove appendMove) {

	}

	@Override
	public void afterAppendMove(TurnCtx turn, AppendMove appendMove) {
		append = true;
	}

	@Override
	public void onAppendMoveFail(TurnCtx turn, AppendMove appendMove) {

	}
}
